﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;
using ShredTheLog.Api;
using ShredTheLog.Api.DataContracts;
using System.Diagnostics.Contracts;

namespace ShredTheLog.Converters
{
    public sealed class ShortUserInfoByKnownLanguagesComparer : IComparer<IShortUserInfo>, IComparer
    {
        public int Compare(object x, object y)
        {
            var x1 = x as IShortUserInfo;
            var y1 = y as IShortUserInfo;
            if (x1 != null && y1 != null)
                return Compare(x1, y1);
            else
                return 0;
        }

        public int Compare(IShortUserInfo x, IShortUserInfo y)
        {
            var x1 = LanguagesConverter.Default.Convert(x.KnownLanguages);
            var y1 = LanguagesConverter.Default.Convert(y.KnownLanguages);
            return String.Compare(x1, y1);
        }

        public static ShortUserInfoByKnownLanguagesComparer Default = new ShortUserInfoByKnownLanguagesComparer();
    }

    public sealed class ShortUserInfoByPracticingLanguagesComparer : IComparer<IShortUserInfo>, IComparer
    {
        public int Compare(object x, object y)
        {
            var x1 = x as IShortUserInfo;
            var y1 = y as IShortUserInfo;
            if (x1 != null && y1 != null)
                return Compare(x1, y1);
            else
                return 0;
        }

        public int Compare(IShortUserInfo x, IShortUserInfo y)
        {
            var x1 = LanguagesConverter.Default.Convert(x.PracticingLanguages);
            var y1 = LanguagesConverter.Default.Convert(y.PracticingLanguages);
            return String.Compare(x1, y1);
        }

        public static ShortUserInfoByPracticingLanguagesComparer Default = new ShortUserInfoByPracticingLanguagesComparer();
    }

    public sealed class ShortUserInfoByCountryComparer : IComparer<IShortUserInfo>, IComparer
    {
        public int Compare(object x, object y)
        {
            var x1 = x as IShortUserInfo;
            var y1 = y as IShortUserInfo;
            if (x1 != null && y1 != null)
                return Compare(x1, y1);
            else
                return 0;
        }

        public int Compare(IShortUserInfo x, IShortUserInfo y)
        {
            var x1 = CountryConverter.Default.Convert(x.Country);
            var y1 = CountryConverter.Default.Convert(y.Country);
            return String.Compare(x1, y1);
        }

        public static ShortUserInfoByCountryComparer Default = new ShortUserInfoByCountryComparer();
    }
}
